package com.ruoyi.common.entity;

import lombok.Data;

@Data
public class ResponseEntity<T> {

    int code;

    String message;

    T data;


    public static final int CODE_OK = 0;

    public static final int CODE_FAIL = 1;

    // 100XX属于权限不足
    public static final int CODE_ERROR_AUTH = 10000;
    public static final int CODE_ERROR_EMPTY_TOKEN = 10001;
    public static final int CODE_ERROR_INVALID_TOKEN = 10002;
    public static final int CODE_ERROR_SEND_SMS = 10003;
    // 101与注册相关
    public static final int CODE_ERROR_REGISTER_FAILED = 10100;
    public static final int CODE_ERROR_USERNAME_EXISTS = 10101;
    public static final int CODE_ERROR_PASSWORD_CHANGE_UNKNOWN = 10102;
    public static final int CODE_ERROR_PASSWORD_CHANGE_OLD_PASSWORD_ERROR = 10103;
    public static final int CODE_ERROR_PASSWORD_CHANGE_ONLY_SELF = 10104;
    public static final int CODE_ERROR_PASSWORD_CHANGE_ILLEGAL_ARGS = 10105;

    public static final int CODE_ERROR_EMAIL_ERROR = 10120;
    public static final int CODE_ERROR_EMAIL_FORMAT_ERROR = 10121;
    public static final int CODE_ERROR_EMAIL_RATE_LIMIT = 10122;
    public static final int CODE_ERROR_EMAIL_EXISTS_ERROR = 10123;
    public static final int CODE_ERROR_EMAIL_NOT_EXISTS_ERROR = 10124;


    public static final int CODE_ERROR_WECHAT_LOGIN_ERROR = 10130;
    public static final int CODE_ERROR_WECHAT_LOGIN_RATE_LIMIT_ERROR = 10131;

    public static final int CODE_ERROR_CAPTCHA_ERROR = 10130;

    public static final int CODE_ERROR_INVITE_CODE_GENERATE_ERROR = 10140;


    // 102 与api key操作有关
    public static final int CODE_ERROR_API_KEY_FAILED = 10200;
    public static final int CODE_ERROR_API_KEY_BALANCE_FAILED = 10201;


    // 103 与chat操作有关
    public static final int CODE_ERROR_CHAT = 10300;
    public static final int CODE_ERROR_CHAT_CONCURRENT_ERROR = 10301;
    public static final int CODE_ERROR_CHAT_SENSITIVE_WORDS_ERROR = 10302;


    public static final int CODE_ERROR_CHAT_LOG_ERROR = 10310;

    // 104 与balance有关
    public static final int CODE_ERROR_BALANCE = 10400;
    public static final int CODE_ERROR_BALANCE_INSUFFICIENT = 10401;
    public static final int CODE_ERROR_BALANCE_TYPE_ERROR = 10402;
    public static final int CODE_ERROR_BALANCE_ILLEGAL = 10403;


    public static final int CODE_ERROR_REDEEM_CODE_ERROR = 10410;
    public static final int CODE_ERROR_REDEEM_CODE_ILLEGAL_KEY_ERROR = 10411;
    public static final int CODE_ERROR_REDEEM_CODE_ILLEGAL_STATE_ERROR = 10412;
    public static final int CODE_ERROR_REDEEM_CODE_ILLEGAL_REDEEM_STATE_ERROR = 10413;

    // 105 user相关
    public static final int CODE_ERROR_USER = 10500;
    public static final int CODE_ERROR_USER_ERROR_ID = 10501;
    public static final int CODE_ERROR_USER_SUPER_ROLE = 10502;

    // 106跟global config有关
    public static final int CODE_ERROR_GLOBAL_CONFIG = 10600;

    // 107跟package有关
    public static final int CODE_ERROR_PACKAGE = 10700;

    // 108跟model有关
    public static final int CODE_ERROR_MODEL = 10800;

    // 109跟platform有关
    public static final int CODE_ERROR_PLATFORM = 10900;

    // reset password
    public static final int CODE_ERROR_RESET_PASSWORD_FAILED = 11500;


    // 110跟file相关
    public static final int CODE_ERROR_FILE = 11000;
    public static final int CODE_ERROR_FILE_LOGO_EXISTS = 11001;


    // 113跟order有关
    public static final int CODE_ERROR_ORDER = 11300;
    public static final int CODE_ERROR_ORDER_LOGIN_FIRST = 11301;
    public static final int CODE_ERROR_REFRESH_AND_TRY_AGAIN = 11302;
    public static final int CODE_ERROR_ORDER_RATE_LIMIT = 11303;
    public static final int CODE_ERROR_ORDER_CONFIG_ERROR = 11304;

    // dashboard
    public static final int CODE_ERROR_DASHBOARD = 11400;


    // 111跟mask有关
    public static final int CODE_ERROR_MASK = 11100;

    // 112跟mask context有关
    public static final int CODE_ERROR_MASK_CONTEXT = 11200;


    public static <T> ResponseEntity<T> ok(String msg, T data) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setCode(CODE_OK);
        entity.setMessage(msg);
        entity.setData(data);
        return entity;
    }

    public static <T> ResponseEntity<T> ok() {
        return ResponseEntity.ok("成功", null);
    }

    public static <T> ResponseEntity<T> ok(T data) {
        return ResponseEntity.ok("成功", data);
    }

    public static <T> ResponseEntity<T> ok(String msg) {
        return ResponseEntity.ok(msg, null);
    }

    public static <T> ResponseEntity<T> fail(String msg) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setCode(CODE_FAIL);
        entity.setMessage(msg);
        return entity;
    }

    public static <T> ResponseEntity<T> fail() {
        return ResponseEntity.fail("失败");
    }
}
